local jueci = fk.CreateSkill {
  name = "lingling__jueci",
}

Fk:loadTranslationTable {
  ["lingling__jueci"] = "决辞",
  [":lingling__jueci"] = "结束阶段，你可以失去1点体力，令一名角色视为使用【杀】，若不为你，其获得一张【杀】，且可以交给你一张牌。",

  ["#lingling__jueci"] = "决辞：是否失去1点体力令一名角色视为使用【杀】，若不为你，其获得一张【杀】",
  ["#lingling__jueci-slash"] = "决辞：请视为使用一张【杀】",
  ["#lingling__jueci-give"] = "决辞：你可以交给 %src 一张牌",
}

jueci:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jueci.name) and player.phase == Player.Finish and player.hp > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = room:askToChoosePlayers(player, {
      targets = room.alive_players,
      min_num = 1,
      max_num = 1,
      prompt = "#lingling__jueci",
      skill_name = jueci.name,
      cancelable = true
    })
    if #to > 0 then
      event:setCostData(self, { tos = to, })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:loseHp(player, 1, jueci.name)
    if to.dead then return end
    room:askToUseVirtualCard(to, {
      name = "slash",
      skill_name = jueci.name,
      prompt = "#lingling__jueci-slash",
      cancelable = false,
      extra_data = {
        bypass_times = true,
        extraUse = true,
      },
    })
    if to.dead then return end
    local cards = room:getCardsFromPileByRule("slash", 1, "allPiles")
    if #cards > 0 then
      room:moveCardTo(cards, Card.PlayerHand, to, fk.ReasonJustMove, jueci.name)
    end
    if player.dead or to.dead or to:isNude() then return end
    cards = room:askToCards(to, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      skill_name = jueci.name,
      prompt = "#lingling__jueci-give:" .. player.id,
      cancelable = true,
    })
    if #cards > 0 then
      room:obtainCard(player, cards, false, fk.ReasonGive, to, jueci.name)
    end
  end,
})

return jueci
